/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ontologia.session;

import com.ontologia.entities.Mediosdetransportes;
import com.ontologia.entities.Paquetes;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Sebastian Rojas
 */
@Stateless
public class PaquetesFacade extends AbstractFacade<Paquetes> {

  @PersistenceContext(unitName = "ontologia-ejbPU")
  private EntityManager em;

  @Override
  protected EntityManager getEntityManager() {
    return em;
  }

  public PaquetesFacade() {
    super(Paquetes.class);
  }

  public void guardarPaquete(Paquetes paquete) {
    em.persist(paquete);
  }

  public Paquetes getPaquetePorPeso(String descripcion) {
    Paquetes paquete = new Paquetes();
    Query query = getEntityManager().createNamedQuery("Paquetes.findByPeso");
    query.setParameter("descripcion", descripcion);
    paquete = (Paquetes) query.getSingleResult();
    return paquete;
  }
  public Paquetes getPaquetePorAtributo(String atributo) {
    Paquetes paquete = new Paquetes();
    switch(atributo) {
      case "maxpeso":
        Query query1 = getEntityManager().createNamedQuery("Paquetes.findByMaxPeso");
        paquete = (Paquetes) query1.getSingleResult();
        break;
      case "minpeso":
        Query query2 = getEntityManager().createNamedQuery("Paquetes.findByMinPeso");
        paquete = (Paquetes) query2.getSingleResult();
        break;
      case "maxtamano":
        Query query3 = getEntityManager().createNamedQuery("Paquetes.findByMaxTamano");
        paquete = (Paquetes) query3.getSingleResult();
        break;
      case "mintamano":
        Query query4 = getEntityManager().createNamedQuery("Paquetes.findByMinTamano");
        paquete = (Paquetes) query4.getSingleResult();
        break;
        
    }
    return paquete;
  }

}
